/**
 * XES Framework
 * xex.js
 * 
 * version 1.6.5
 * @upload 2011-04-14
 * @author Jay
 */
$(function(){
/*
	if ($('.xes_menu').length > 0) {
		xesMenu();
	}

	if(window.location.href.split('.com/').length>1){
		show53kf();		
	}
*/
	//newInquiry();
	// 头部搜索 回车提交
	$('#head_keyword').keyup(function(e){
		if(e.keyCode == 13){  
			headSearch();  
		}
	});
	
	// 头部登录 回车提交
	$('#head_username').add('#head_password').keyup(function(e){
		if(e.keyCode == 13){  
			headUserLogin(); 
			$(this).blur();
		}
	});	
	//下拉
	
	$('#gz_tit_0120').hover(
		function(){
			$(this).find('#gz_tit_0120_inner').show();
		},
		function(){
			$(this).find('#gz_tit_0120_inner').hide();
		}
	);	

	//用户登录框效果
	if($('#userInfo1').length>0){
		//判断用户登录
		callUserInfo();
		$('#indexUserInfo').submit(function(){
			indexUserLogin();
		});
		userloginInputClick();
	}
	//用户反馈
	feedbackBtn();

});
var localhostName = document.location.host;
/*
$(window).resize(function(){
	var _head=$('.nav_0118');
	$('.xes_menu[id!="indexMenu"]').css({
		left:_head.offset().left
	}).show();	
});
*/
/*
 * XES Menu
 */
function xesMenu(){
	var _head=/*$('.header').length>0?$('.header'):*/$('.nav_0118');
	$('.xes_menu[id!="indexMenu"]').css({
		left:_head.offset().left
	}).show();	
	$('.xes_menu li').removeClass('on');
	$('.xes_menu li').hover(function(){
		$(this).addClass('on').siblings('li').removeClass('on');
	});
	if ($('.xes_menu').length > 0) {
		$('body[id!="index2"]').bind('mousemove', function(e){
			if (!isMouseOnCategory(e, $('.xes_menu')[0])) {
				xesMenuHide();
			}
		});
	}
	$('.xes_menu_handle').mousemove(function(){
		xesMenuShow();
	});
}
function xesMenuShow(){
	$('.xes_menu ul').show();
	$('.xes_menu_handle').addClass('on');
}
function xesMenuHide(){
	$('.xes_menu ul').animate({
		opacity:'hide'
	},'fast');
	$('.xes_menu_handle').removeClass('on');
}
/*
 * 用户登录框
 */
function userloginInputClick() {
	var _user=$('#index_username');
	var _pass=$('#index_password');
	var _pass0=$('#index_password_0');
	var _val=_user.val();
	_user.blur(function(){
		if(this.value==''){
			this.value='会员名/邮箱/手机号';
		}
	}).focus(function(){
		if(this.value=='会员名/邮箱/手机号'){
			this.value='';
		}
	});
	_pass0.focus(function(){   
		_pass.show().focus();   
		_pass0.hide();   
	});   
	_pass.blur(function(){   
		if(_pass.val()=='') {   
			_pass0.show();   
			_pass.hide();   
		}   
	});

}

function indexUserLogin () {
	var username=$.trim($("#index_username").val());
	var password=$.trim($("#index_password").val());
	var params="data[Cas][username]="+username+"&data[Cas][password]="+password;
	var _a=window.location.host,
		//_url=_a=='www.wss2.0.com'?'logintest.xueersi.org':'login.xueersi.org';
		_url=_a=='www.xueersi.com'?'login.xueersi.org':'logintest.xueersi.org';
    if (username == '邮箱/手机/用户名') {
    	alert('请填写用户名！');
    	return false;
    }

    $.ajax({
        type: "post",
        url: '/users/userLogin',
        dataType: "json",
        timeout: 10000,
        data: params,
       success: function(msg) {
            if(msg.sign == true){
				if($('#iframe')){
					$('#iframe').remove();
				}
				$("#casiframe").append('<iframe src="http://'+_url+'/cas/actlogin/?tk='+msg.casid+'" width="0" height="0" style = "display:none"></iframe>');
				$("#userInfo1").hide();
				$("#userInfoLoading").show();
				callUserInfo();
            }else{
                alert(msg.loginErrorMsg);
            }
        },
        error: function () {
            alert('数据读取错误..');
        }
    });
}

/* 返回用户信息  */

function callUserInfo(){
	var _hostName = document.location.host;
	var url='http://' + _hostName + '/users/getSpUrl?jsoncallback=?';
	$.getJSON(url,function(d){
		var _order=d.ordernum!=null?d.ordernum:0,
			_user=d.name!=null?d.name:'';
		if(d.name!=null){
			$('#ordernum').text(_order);
			$('#userInfo2 .info1').text(_user+'同学，欢迎您来到学而思网校！');
			var htmlTitle = $($('.welcome_info')[1]);
			htmlTitle.html(''+_user+',欢迎您!&nbsp;&nbsp;&nbsp;<a href="http://i.xueersi.com/"  xes_id="banner14">个人中心</a>&nbsp;&nbsp;&nbsp;<a href="http://'+_hostName+'/users/logout/" xes_id="banner15">退出</a>');
			$("#userInfo1").hide();
			$("#userInfo2").show();
			$("#userInfoLoading").hide();
	}else{
			$('#userInfo1').show();
			$('#userInfo2,#userInfoLoading').hide();
		}
	});
}

//tab 可在同一页用多次
function tabs(tabTit,curr,tabCon){
	$(tabCon).each(function(){
		$(this).children().eq(0).show();
	});
	$(tabTit).children().click(function(){
		$(this).addClass(curr).siblings().removeClass(curr);
		var index = $(tabTit).children().index(this);
		$(tabCon).children().eq(index).show().siblings().hide();
	});
}

function scroll(a, b, c, d, e) {
    var EACH = function (o, fn) {
        for (var i = 0; i < o.length; i++) {
            fn.call(o[i], i, o)
        }
    };
    var GF = function (o, t) {
        var s = o.getElementsByTagName(t),
            R = [];
        EACH(s, function (i, v) {
            s[i].parentNode == o && R.push(s[i]);
        });
        return R;
    };
    var G = function (x, y) {
        return GF(document.getElementById(x), y);
    };
    var T = G(a, b),
        S = G(c, d);
    _show(0);
    EACH(T, function (i, o) {
        T[i].onmouseover = (function (n) {
            return function () {
                _show(n);
            }
        })(i);
    });

    function _show(n) {
        EACH(T, function (i, o) {
            S[i].style.display = "none";
            T[i].className = ""
        });
        T[n].className = e;
        S[n].style.display = "block";
    }
}

function DomFix(d) {
    var isIE6 = /MSIE 6\./.test(navigator.userAgent) && !window.opera;
    if (isIE6) {
        var menuYloc = $(d).offset().top;
        $(window).scroll(function () {
            var offsetTop = menuYloc + $(window).scrollTop() + "px";
            $(d).animate({
                top: offsetTop
            },
            {
                duration: 600,
                queue: false
            });
        });
    } else {}
}

function feedbackBtn() {
    var _html = '<div class="research" id="FeedBackBtn">' + ' <div class="float_search_box">' + '  <div class="homepage_searchbtn">' + '     <a target="_blank" href="/Help/feedback">&nbsp;</a>' + '  </div>' + ' </div>' + '</div>';
    if ($('#FeedBackBtn').length == 0) {
        $('body').append(_html);
    }
    DomFix($("#FeedBackBtn")[0]);
}

function show53kf() {
    var _href = window.location.href.split('.com/')[1].split('/')[0];
    var isMyCenter = window.location.href.split('i.xueersi.com').length > 1 ? true : false;
    var _html = '<div id="kfDiv" style="width:101px;height:171px; position:fixed; _position:absolute;right:6px;top:140px; display:block">' + '<iframe frameborder="0" style="position: absolute; z-index: 7998; width: 0px; height: 0px; top: 0px; left: 0px;"></iframe>' + '<div id="kfIconDivMain" style="z-index: 7999; top: 3px; width: 101px; height: 171px; overflow: hidden; position: absolute;"><img class="kf_close" src="http://www.xueersi.com/img/xes_kf_close.gif" onclick="show53kf_close();" style="position: absolute; right: 0px; top: 0px; cursor: pointer;"><img src="http://www.xueersi.com/img/xes_kf.jpg" style="cursor: pointer;" onclick="show53kf_open();"></div>' + '</div>';
    if (!isMyCenter) {
        $('body').append(_html);
        DomFix($("#kfDiv")[0]);
    }
}

function show53kf_open() {
    var _url = location.href.split("?");
    var openUrl = 'http://zt.xueersi.com/kefu.htm?arg=eduukf&style=1&referer=' + _url[0] + '&charset=utf-8';
    try {
        window.open(openUrl, "_blank", "height=473,width=703,top=200,left=200,status=yes,toolbar=no,menubar=no,resizable=no,scrollbars=no,location=no,titlebar=no");
    } catch(e) {}
}

function show53kf_close() {
    var _kf = $('#kfDiv');
    if (_kf.length > 0) {
        _kf.remove();
    }
}

function newInquiry() {
    var _html = '<div id="inquiryBox">' + '<iframe frameborder="0"></iframe>' + '<div id="inquiryBoxMain"><a href="http://www.xueersi.com/votes/view/10014" target="_blank"><img src="http://file.xueersi.com/web/12992431199699.png" ></a></div>' + '</div>';
    $('body').append(_html);
    DomFix($("#inquiryBox")[0]);
}

function dialogRB(pic, url, title) {
	var _html='<div id="winDiv" xes_id="dialogRB_grade5" class="winDiv" style="display: block;height: 180px;position: fixed;right: 6px;bottom:0px;width: 250px;background-color:#ce0010;_position: absolute;_overflow: hidden;display:none">'
					+' <ul id="winDivMain" style="height: 180px;width: 250px;overflow: hidden;position: absolute;top: 3px;z-index: 7999;">'
					+'   <li style="margin:3px 8px;color:#fff;font-weight: bold;">'
					+'     <img src="http://www.xueersi.com/images/xesDialog_title.png"/><img id="winDiv_close" style="margin-left: 80px;cursor: pointer;" src="http://www.xueersi.com/images/xesDialog_closeBtn.png"/>'
					+'   </li>'
					+'   <li style="margin:0 5px 5px 5px;background-color:#fff;height:145px;">'
					+'     <a href="'+url+'" target="_blank" title="'+title+'"><img alt="'+title+'" src="'+pic+'" /></a>'
					+'   </li>'
					+' </ul>'
					+'</div>';
    if ($('#winDiv').length == 0) {
        $('body').append(_html);
    }
    var _box = $("#winDiv");
    var _closeBtn = _box.find('#winDiv_close');
    _closeBtn.live('click', function () {
        _box.hide();
    });
    _box.css('top', $(window).height() - 180);
    _box.show();
    var isIE6 = /MSIE 6\./.test(navigator.userAgent) && !window.opera;
    if (isIE6) {
        var menuYloc = _box.offset().top;
        $(window).scroll(function () {
            var offsetTop = menuYloc + $(window).scrollTop() + "px";
            _box.animate({
                top: offsetTop
            },
            {
                duration: 600,
                queue: false
            });
        });
    } else {
        _box.css('position', 'fixed');
    }
}

function xes_dialog(conf) {
    var _date = new Date(),
        _week = _date.getDay(),
        _today = _date.getFullYear() + '/' + (_date.getMonth() + 1) + '/' + _date.getDate();
    var _data = [{
        grade: [2, 3, 4, 5, 6, 7],
        week: [0, 5, 6],
        title: '抢报小学暑期课程 立省20~30元 优惠期截止：6月1日',
        url: 'http://zt.xueersi.com/xiaoxue/xhzczt/',
        img: 'http://file.xueersi.com/web/13045988996877.jpg',
        endDay: '2011/6/1'
    },
    {
        grade: [2, 3, 4, 5, 6, 7],
        week: [1, 2, 3, 4],
        title: '网校整套学习方案，一天3块钱，一年学习有保障！',
        url: 'http://zt.xueersi.com/zt_nianka/',
        img: 'http://file.xueersi.com/web/13057157361997.jpg',
        endDay: '2011/6/1'
    },
    {
        grade: [8, 9, 10],
        week: [0, 5, 6],
        title: '初中暑期班限时抢报  立省20~30元 优惠期截止：6月1日',
        url: 'http://zt.xueersi.com/zt_chuzhong/czhzzt/',
        img: 'http://file.xueersi.com/web/13045989274437.jpg',
        endDay: '2011/6/1'
    },
    {
        grade: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
        week: [1, 2, 3, 4],
        title: '我想要这样的网校社区——我的地盘我做主',
        url: 'http://www.xueersi.com/votes/view/10018',
        img: 'http://file.xueersi.com/web/13045989422075.jpg',
        endDay: '2011/5/12'
    }];
    $.each(_data, function (i) {
        var __d = _data[i];
        var __isGrade = $.inArray(conf.grade, _data[i].grade) == -1 ? false : true;
        var __isWeek = $.inArray(_week, _data[i].week) == -1 ? false : true;
        var __s1 = new Date(_today),
            __s2 = new Date(_data[i].endDay);
        var __times = __s2.getTime() - __s1.getTime();
        var __days = parseInt(__times / (1000 * 60 * 60 * 24)) + 1;
        if (__isGrade && __isWeek && __days > 0) {
            dialogRB(__d.img, __d.url, __d.title);
        } else {
            return;
        }
    });
}

function slideSwitch(dom) {
    var _box = dom || $('.banner');
    _box.each(function () {
        var active = $(this).find('a.active');
        if (active.length == 0) {
            active = $(this).find('a:last');
        }
        var next = active.next().length ? active.next() : $(this).find('a:first');
        active.addClass('last-active');
        next.css({
            opacity: 0.0
        }).addClass('active').animate({
            opacity: 1.0
        },
        1000, function () {
            active.removeClass('active last-active');
        });
    });
};
(function ($) {
    $.fn.extend({
        RollTitle: function (opt, callback) {
            if (!opt) {
                var opt = {};
            }
            var _this = this;
            _this.timer = null;
            _this.lineH = _this.find("li:first").height();
            _this.line = opt.line ? parseInt(opt.line, 15) : parseInt(_this.height() / _this.lineH, 10);
            _this.speed = opt.speed ? parseInt(opt.speed, 10) : 3000;
            _this.timespan = opt.timespan ? parseInt(opt.timespan, 13) : 5000;
            if (_this.line == 0) {
                this.line = 1;
            }
            _this.upHeight = 0 - _this.line * _this.lineH;
            _this.scrollUp = function () {
                _this.animate({
                    marginTop: _this.upHeight
                },
                _this.speed, function () {
                    for (i = 1; i <= _this.line; i++) {
                        _this.find("li:first").appendTo(_this);
                    }
                    _this.css({
                        marginTop: 0
                    });
                });
            };
            _this.hover(function () {
                clearInterval(_this.timer);
            },


            function () {
                _this.timer = setInterval(function () {
                    _this.scrollUp();
                },
                _this.timespan);
            }).mouseout();
        }
    })
})(jQuery);
(function ($) {
    $.fn.xesMarquee = function (o) {
        o = $.extend({
            speed: 30,
            step: 1,
            direction: "up",
            visible: 1
        },
        o || {});
        var i = 0;
        var div = $(this);
        var ul = $("ul", div);
        var tli = $("li", ul);
        var liSize = tli.size();
        if (o.direction == "left") {
            tli.css("float", "left");
        }
        var liWidth = tli.innerWidth();
        var liHeight = tli.height();
        var ulHeight = liHeight * liSize;
        var ulWidth = liWidth * liSize;
        if (liSize > o.visible) {
            ul.append(tli.slice(0, o.visible).clone())
            li = $("li", ul);
            liSize = li.size();
            div.css({
                "position": "relative",
                overflow: "hidden"
            });
            ul.css({
                "position": "relative",
                margin: "0",
                padding: "0",
                "list-style": "none"
            });
            li.css({
                margin: "0",
                padding: "0",
                "position": "relative"
            });
            switch (o.direction) {
            case "left":
                div.css("width", (liWidth * o.visible) + "px");
                ul.css("width", (liWidth * liSize) + "px");
                li.css("float", "left");
                break;
            case "up":
                div.css({
                    "height": (liHeight * o.visible) + "px"
                });
                ul.css("height", (liHeight * liSize) + "px");
                break;
            }
            var _MyMar = setInterval(_xMarquee, o.speed);
            ul.hover(function () {
                clearInterval(_MyMar);
            },


            function () {
                _MyMar = setInterval(_xMarquee, o.speed);
            });
        };

        function _xMarquee() {
            if (o.direction == "left") {
                if (div.scrollLeft() >= ulWidth) {
                    div.scrollLeft(0);
                } else {
                    var leftNum = div.scrollLeft();
                    leftNum += parseInt(o.step);
                    div.scrollLeft(leftNum)
                }
            }
            if (o.direction == "up") {
                if (div.scrollTop() >= ulHeight) {
                    div.scrollTop(0);
                } else {
                    var topNum = div.scrollTop();
                    topNum += parseInt(o.step);
                    div.scrollTop(topNum);
                }
            }
        };
    };
})(jQuery);

function GetRandom(n) {
    var GetRandomn = parseInt(Math.floor(Math.random() * n + 1));
    return GetRandomn;
}(function () {
    $.extend({
        format: function (str, step, splitor) {
            str = str.toString();
            var len = str.length;
            if (len > step) {
                var l1 = len % step,
                    l2 = parseInt(len / step),
                    arr = [],
                    first = str.substr(0, l1);
                if (first != '') {
                    arr.push(first);
                };
                for (var i = 0; i < l2; i++) {
                    arr.push(str.substr(l1 + i * step, step));
                };
                str = arr.join(splitor);
            };
            return str;
        }
    });
})(jQuery);

function isMouseOnCategory(e, d) {
    var e = e || window.event;
    var x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
    var y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
    var cate = $(d);
    var cL1 = cate.offset().left,
        cL2 = cL1 + cate.outerWidth(),
        cT1 = cate.offset().top,
        cT2 = cT1 + cate.outerHeight();
    if (x > cL1 && y > cT1 && x < cL2 && y < cT2) {
        return true;
    } else {
        return false;
    }
}

function addFav(url, title) {
    if (window.sidebar) {
        window.sidebar.addPanel(title, url, "");
    } else if (document.all) {
        var external = window.external;
        external.AddFavorite(url, title);
    } else if (window.opera && window.print) {
        return true;
    }
}

function setHits(arr, func) {
    $.each(arr, function (i) {
        arr[i].btn.live('mousedown', function () {
            return func(arr[i].id);
        });
    });
}
var lazyLoad = {
    Init: function () {
        return $("img[lazyload]");
    },
    Calculate: function (lazyloadobject) {
        var windowHeight = $(window).height();
        var arrReturn = {};
        var _scrollTop;
        if (lazyloadobject.length == 0) {
            return null;
        } else {
            lazyloadobject.each(function (i) {
                _scrollTop = parseInt($(this).offset().top - windowHeight);
                if (!arrReturn.hasOwnProperty(_scrollTop)) {
                    arrReturn[_scrollTop] = new Array();
                }
                arrReturn[_scrollTop].push($(this));
            });
            this.ArrLoad = arrReturn;
            return arrReturn;
        }
    },
    ArrLoad: null,
    IsLoad: function (scrolltop, objectstop) {
        if (objectstop != null && objectstop != {}) {
            for (i in this.ArrLoad) {
                if (parseInt(i) <= scrolltop && this.ArrLoad.hasOwnProperty(i)) {
                    for (j = 0; j < this.ArrLoad[i].length; j++) {
                        this.ArrLoad[i][j].attr("src", this.ArrLoad[i][j].attr("lazyload")).removeAttr("lazyload");
                    }
                    delete this.ArrLoad[i];
                }
            }
        }
    },
    Run: function () {
        var lazyLoadObject = this.Init();
        this.Calculate(lazyLoadObject);
        arrScrollTop = this.ArrLoad;
        if (arrScrollTop == null) {
            return false;
        } else {
            var _this = this;
            _this.IsLoad($(window).scrollTop(), arrScrollTop);
            $(window).scroll(function () {
                _this.IsLoad($(this).scrollTop(), arrScrollTop);
            });
        }
    }
};
$(function () {
    lazyLoad.Run();
});
$(window).resize(function () {
    lazyLoad.Run();
});
var xesCookie = {
    set: function (name, value, seconds) {
        seconds = seconds || 0;
        var expires = "";
        if (seconds != 0) {
            var date = new Date();
            date.setTime(date.getTime() + (seconds * 1000));
            expires = "; expires=" + date.toGMTString();
        }
        document.cookie = name + "=" + escape(value) + expires + "; path=/";
    },
    get: function (name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') {
                c = c.substring(1, c.length);
            }
            if (c.indexOf(nameEQ) == 0) {
                return unescape(c.substring(nameEQ.length, c.length));
            }
        }
        return false;
    },
    clear: function (name) {
        xesCookie.set(name, "", -1);
    },
    del: function (name) {
        var exp = new Date();
        exp.setTime(exp.getTime() - 1);
        var cval = xesCookie.get(name);
        if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
    }
};

function videoShow(config) {
    var o = config || {};
    o.ID = config.id || '18947';
    o.width = config.width || '470';
    o.height = config.height || '286';
    o.version = config.ver || '1.4';
    o.flashVersion = '10.1.52';
    o.imgUrl = config.picUrl;
    o.statsID = config.hitID || '';
    o.autoPlay = config.auto || false;
    o.videoID = config.FlashID || 'focusVideo';
    o.type = config.type;
    var flashvars = {};
    flashvars.url = "http://i.xueersi.com";
    flashvars.id = o.ID;
    flashvars.imgUrl = o.imgUrl;
    flashvars.statsID = o.statsID;
    flashvars.autoPlay = o.autoPlay;
    flashvars.type = o.type;
    var params = {};
    params.allowFullScreen = true;
    params.quality = "high";
    params.wmode = "opaque";
    params.allowscriptaccess = "sameDomain";
    var attributes = {};
    swfobject.embedSWF("http://www.xueersi.com/flash/videoplayer_f_v" + o.version + ".swf", o.videoID, o.width, o.height, o.flashVersion, " http://zt.xueersi.com/video/expressInstall.swf", flashvars, params, attributes);
}

function headSearch() {
    var hostName = document.location.host;
    if (hostName == 'bbs.xueersi.com') {
        hostName = 'www.xueersi.com';
    }
    var url = 'http://' + hostName + '/search';
    var _val = $.trim($('#head_keyword').val());
    if ((_val != '') && (_val != '老师名或课程名')) {
        url += '?keyword=' + encodeURI($.trim($('#head_keyword').val()));
    }
    window.top.location.href = url;
};

function huodong(url) {
    $.getJSON('http://' + localhostName + '/users/getSpUrl?jsoncallback=?', function (d) {
        var _name = d.name == null ? '' : d.name,
        _realname = d.realname == null ? '' : d.realname;
        var _url = url + '?name=' + _name + '&realname=' + _realname + '&code=' + d.code;
        window.location.href = _url;
    });
}

function head_search() {
    url = '/course/search/';
    url += 'grade:' + $('#head_grade').val() + '/';
    url += 'subject:' + $('#head_subject').val() + '/';
    url += 'keywords:' + $.trim($('#head_keywords').val()) + '/';
    window.location.href = url;
};

function headUserLogin() {
    var username = $.trim($("#head_username").val());
    var password = $.trim($("#head_password").val());
    var params = "username=" + username + "&password=" + password;
    if (username == '邮箱/手机/用户名') {
        alert('请填写用户名！');
        return false;
    }
    $.ajax({
        type: "post",
        url: '/users/userLogin',
        dataType: "json",
        timeout: 7000,
        data: params,
        success: function (msg) {
            if (msg.sign == true) {
                $("#userInfo1").hide();
                $("#userInfo2").show();
                $("#userLoginname").html(username);
            } else {
                alert(msg.loginErrorMsg);
            }
        },
        error: function () {
            alert('数据读取错误..');
        }
    });
};

function myUserLogin() {
    var username = $.trim($("#username").val());
    var password = $.trim($("#password").val());
    var params = "username=" + username + "&password=" + password;
    $.ajax({
        type: "post",
        url: '/users/userLogin',
        dataType: "json",
        timeout: 7000,
        data: params,
        success: function (msg) {
            if (msg.sign == true) {
                $("#userBox").hide();
                $("#userInfo1").hide();
                $("#userInfo2").show();
                $("#userLoginname").html(username);
            } else {
                alert(msg.loginErrorMsg);
            }
        },
        error: function () {
            alert('数据读取错误..');
        }
    });
};

function myCartLogin() {
    var username = $.trim($("#username").val());
    var password = $.trim($("#password").val());
    var params = "username=" + username + "&password=" + password;
    $.ajax({
        type: "post",
        url: '/users/userLogin',
        dataType: "json",
        timeout: 7000,
        data: params,
        success: function (msg) {
            if (msg.sign == true) {
                window.location.href = "/shoppingcart/mycart/showLogin";
            } else {
                alert(msg.loginErrorMsg);
            }
        },
        error: function () {
            alert('数据读取错误..');
        }
    });
};

function showRegisterTab() {
    $('#register_tab').addClass('on');
    $('#login_tab').removeClass('on');
    $('#register_box').show();
    $('#login_box').hide();
}

function myCartReg() {
    var email = $.trim($("#email").val());
    var password = $.trim($("#regpassword").val());
    var confirm_password = $.trim($("#repassword").val());
    var realname = $.trim($("#truename").val());
    var phone = $.trim($("#mobile").val());
    var phone_province = $.trim($("#phone_province").val());
    var phone_city = $.trim($("#phone_city").val());
    var grade_id = $.trim($("#grade").val());
    var verificationCode = $.trim($("#code").val());
    var allowClause = $.trim($("#provisions").val());
    var ip_province = $.trim($("#ip_province").val());
    var ip_city = $.trim($("#ip_city").val());
    var params = "email=" + email + "&password=" + password + "&confirm_password=" + confirm_password + "&realname=" + realname + "&phone=" + phone + "&phone_province=" + phone_province + "&phone_city=" + phone_city + "&grade_id=" + grade_id + "&verificationCode=" + verificationCode + "&allowClause=" + allowClause + "&ip_province=" + ip_province + "&ip_city=" + ip_city;
    $.ajax({
        type: "post",
        url: '/users/aRegister',
        dataType: "json",
        timeout: 7000,
        data: params,
        success: function (msg) {
            if (msg.sign == true) {
                $("#cartLogin").html('<div class="cartRegSucc"><img src="/img/smiling-face.gif" /><span class="cartRegWord">注册成功！</span>3秒后转入订单确认...</div>');
                setTimeout("makeOrder();", 3000);
            } else {
                alert(msg.regErrorMsg);
            }
        },
        error: function () {
            alert('数据读取错误..');
        }
    });
};

function hideElement(element) {
    $("#" + element).hide();
};

function getElementPos(elementId) {
    var ua = navigator.userAgent.toLowerCase();
    var isOpera = (ua.indexOf('opera') != -1);
    var isIE = (ua.indexOf('msie') != -1 && !isOpera);
    var el = document.getElementById(elementId);
    if (el.parentNode === null || el.style.display == 'none') {
        return false;
    }
    var parent = null;
    var pos = [];
    var box;
    if (el.getBoundingClientRect) {
        box = el.getBoundingClientRect();
        var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
        var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
        return {
            x: box.left + scrollLeft,
            y: box.top + scrollTop
        };
    } else if (document.getBoxObjectFor) {
        box = document.getBoxObjectFor(el);
        var borderLeft = (el.style.borderLeftWidth) ? parseInt(el.style.borderLeftWidth) : 0;
        var borderTop = (el.style.borderTopWidth) ? parseInt(el.style.borderTopWidth) : 0;
        pos = [box.x - borderLeft, box.y - borderTop];
    } else {
        pos = [el.offsetLeft, el.offsetTop];
        parent = el.offsetParent;
        if (parent != el) {
            while (parent) {
                pos[0] += parent.offsetLeft;
                pos[1] += parent.offsetTop;
                parent = parent.offsetParent;
            }
        }
        if (ua.indexOf('opera') != -1 || (ua.indexOf('safari') != -1 && el.style.position == 'absolute')) {
            pos[0] -= document.body.offsetLeft;
            pos[1] -= document.body.offsetTop;
        }
    }
    if (el.parentNode) {
        parent = el.parentNode;
    } else {
        parent = null;
    }
    while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML') {
        pos[0] -= parent.scrollLeft;
        pos[1] -= parent.scrollTop;
        if (parent.parentNode) {
            parent = parent.parentNode;
        } else {
            parent = null;
        }
    }
    return {
        x: pos[0],
        y: pos[1]
    };
};

function shopcartAdd(id) {
    var pos = getElementPos("img" + id);
    $.ajax({
        url: '/course/cart/' + id,
        type: 'get',
        dataType: 'html',
        success: function (msg) {
            $("#shopcartBox").html(msg);
            $("#shopcartBox").show();
            var a = document.getElementById("shopcartBox");
            a.style.left = pos.x - 450 + "px";
            a.style.top = pos.y + "px";
            return true;
        }
    });
};

function addBuyCar(d) {
    var _box = $(d).parents('tr'),
        _a = _box.find('td:first a'),
        _id = _a.attr('id');
    $.ajax({
        url: '/course/Acart/',
        type: 'post',
        dataType: "json",
        data: 'id=' + _id,
        timeout: 7000,
        success: function (msg) {
            switch (msg.result) {
            case 1:
                buyCarAnimate(d);
                if (msg.total[0] != 0) {
                    var _box = $('#buyCarBox').find('tbody');
                    _box.empty();
                    $.each(msg.cartList, function (i, n) {
                        buyCarCreatItem(i, n.pname, n.price, n.resale, n.pnum);
                    });
                }
                $('#buyCarBox .buycar_count span').text(msg.total[0]);
                $('#buyCarBox .buycar_price_all span').text(msg.total[1]);
                $('#buyCarBtn a em').text(msg.total[0]);
                $('#index_xes div.list_nav div.navBox span.number').text(msg.total[0]);
                buyCarSetColor();
                break;
            case 2:
                alert('您已购买过此课程!');
                break;
            case 3:
                alert('添加到购物车失败!');
                break;
            default:
                break;
            }
        }
    });
};

function buyCarSetColor() {
    $('#buycar_list tbody tr:even').removeClass('gray');
    $('#buycar_list tbody tr:odd').addClass('gray');
};

function buyCarCreatItem(id, name, price, resale, num) {
    var _box = $('#buyCarBox').find('tbody'),
        _num = _box.find('tr').length,
        _serial = (_num < 10) ? ('0' + (_num + 1)) : (_num + 1);
    var _html = '<tr id="cart' + id + '" class="gray">' + ' <td class="buycar_serial">' + _serial + '</td>' + ' <td class="buycar_title"><a href="/kc/' + id + '.html" target="_blank">' + name + '</a></td>' + ' <td class="buycar_num">' + num + '</td>' + ' <td class="buycar_price">￥' + resale + '</td>' + ' <td class="buycar_delete"><a href="javascript:void(0);">删除</a></td>' + '</tr>';
    _box.append(_html);
};

function buyCarAnimate(d) {
    var _dom = $(d).parents('tr'),
        _btn = $('#buyCarBtn a em');
    var _wrap = '<div id="buyCarAnimateWrap"></div>';
    $('body').append(_wrap);
    $('#buyCarAnimateWrap').css({
        top: _dom.offset().top,
        left: _dom.offset().left,
        width: _dom.width(),
        height: _dom.height()
    }).show();
    $('#buyCarAnimateWrap').animate({
        width: 0,
        height: 0,
        top: _btn.offset().top + 5,
        left: _btn.offset().left
    },
    600, function () {
        $('#buyCarAnimateWrap').hide();
    });
};

function buyCarDelete(id) {
    $.ajax({
        url: '/shoppingcart/aDelCart/',
        type: 'post',
        dataType: "json",
        data: 'id=' + id,
        timeout: 7000,
        success: function (msg) {
            if (msg.result == true) {
                var _box = $('#buyCarBox').find('tbody');
                if (msg.total[0] == 0) {
                    _box.html('<tr><td colspan="5" align="center">没有任何记录！</td></tr>');
                } else {
                    _box.empty();
                    $.each(msg.cartList, function (i, n) {
                        buyCarCreatItem(i, n.pname, n.price, n.resale, n.pnum);
                    });
                }
                $('#buyCarBox .buycar_count span').text(msg.total[0]);
                $('#buyCarBox .buycar_price_all span').text(msg.total[1]);
                $('#buyCarBtn a em').text(msg.total[0]);
                $('#index_xes div.list_nav div.navBox span.number').text(msg.total[0]);
                buyCarSetColor();
            }
        }
    });
};

function buyCarClear() {
    $.ajax({
        url: '/shoppingcart/aEmptyCart/',
        type: 'post',
        dataType: "json",
        timeout: 7000,
        success: function (msg) {
            if (msg.result == true) {
                var _box = $('#buyCarBox').find('tbody');
                if (msg.total[0] == 0) {
                    _box.html('<tr><td colspan="5" align="center">没有任何记录！</td></tr>');
                } else {
                    _box.empty();
                    $.each(msg.cartList, function (i, n) {
                        buyCarCreatItem(i, n.pname, n.price, n.resale, n.pnum);
                    });
                }
                $('#buyCarBox .buycar_count span').text(msg.total[0]);
                $('#buyCarBox .buycar_price_all span').text(msg.total[1]);
                $('#buyCarBtn a em').text(msg.total[0]);
                $('#index_xes div.list_nav div.navBox span.number').text(msg.total[0]);
            }
        }
    });
};

function buyCarIeHack(d, b, r) {
    var wH = $(window).height();
    var wW = $(window).width();
    var sT = $(document).scrollTop();
    var dW = d.outerWidth();
    var dH = d.outerHeight();
    var T = wH - dH + sT - b;
    var L = wW - dW - r;
    d.css({
        position: 'absolute',
        top: T,
        left: L
    });
};

function hoverShow(classid, indexid, divid) {
    $("." + classid).hover(function () {
        var id = $(this).attr(indexid);
        var pos = getElementPos(id);
        $("#" + divid + id).show();
        var a = document.getElementById(divid + id);
        a.style.left = pos.x + 10 + "px";
        a.style.top = pos.y + 20 + "px";
    },


    function () {
        var id = $(this).attr(indexid);
        $("#" + divid + id).hide();
    });
};

function makeOrder(type) {
    $.ajax({
        url: '/shoppingcart/makecart/',
        type: 'post',
        dataType: 'html',
        success: function (msg) {
            if (msg == 0) {
                var H = Math.max($('body').height(), $(window).height()),
                    L = $('body').width() / 2 - 235;
                var _mask = '<div id="winMask" class="win-mask"><!--[if IE 6]><iframe frameborder="0" width="100%" height="100%" style="filter:alpha(opacity=0);opacity:0;"></iframe><![endif]--></div>';
                if ($('#winMask').length == 0) {
                    $('body').append(_mask);
                }
                $('#winMask').height(H).show();
                var pos = getElementPos("img");
                $("#cartLogin,.win-form-box:eq(0)").show();
                $("#cartname").focus();
                var b = document.getElementById("cartLogin");
                b.style.left = L + "px";
                b.style.top = pos.y - 200 + "px";
                var _scroll = $('#img').length > 0 ? $('#img').offset().top : 50;
                if (type == 'register') {
                    showRegisterTab();
                }
                return true;
            }
            if (msg == 1) {
                window.location.href = "/orders/add/";
                return true;
            } else {
                var arr = new Array();
                arr = msg.split("@|@");
                var ids = new Array();
                ids = arr[0].split(",");
                alert(arr[1]);
                for (var i = 0; i < ids.length; i++) {
                    tr = document.getElementById("cart" + ids[i]);
                    tr.style.backgroundColor = "#F5D3D3";
                }
                return false;
            }
        }
    });
};

function paymenttype() {
    $("div[name=paymenttype_div]").each(function (i, n) {
        $(this).hover(function () {
            $(this).css('background-color', '#C8E4FC');
            $(this).css('cursor', 'pointer');
        },


        function () {
            $(this).css('background-color', '#F9FCFE');
        });
        $(this).click(function () {
            document.getElementById('paymentradio' + i).checked = true;
            $("span[name=paymenttype]").attr('class', 'bold');
            $("#paymenttype" + i).attr('class', 'orangebold');
            $("div[name=payment]").slideUp();
            $("#payment" + i).slideDown("normal");
        });
    });
};

function mypaymenttype() {
    var mypaymenttype = $("#mypaymenttype").val();
    if (mypaymenttype >= 0) {
        document.getElementById('paymentradio' + mypaymenttype).checked = true;
        $("#payment" + mypaymenttype).show();
        $("#paymenttype" + mypaymenttype).attr('class', 'orangebold');
    }
};

function getCounpon(cid, sel_id) {
    if (course[cid] == undefined) {
        return false;
    }
    $("#" + sel_id).html('<option value="">选择奖学金</option>');
    var len = coupon.length;
    for (i = 0; i < len; i++) {
        if (coupon[i][3] == 1) {
            continue;
        }
        if (coupon[i][2] != '') {
            var _str = ',' + coupon[i][2] + ',';
            if (_str.indexOf(',' + cid + ',') == -1) {
                continue;
            }
        }
        addOption(i, sel_id);
    }
};

function addOption(id, sel_id) {
    var _html = $("#" + sel_id).html();
    $("#" + sel_id).html(_html + '<option value="' + coupon[id][0] + '">' + coupon[id][1] + '元-' + coupon[id][4] + '</option>');
};

function selCoupon(id) {
    coupon[id][3] = 1;
};

function changeAdd() {
    $("div[name=add_div]").each(function (i, n) {
        $(this).hover(function () {
            $(this).css('background-color', '#C8E4FC');
            $(this).css('cursor', 'pointer');
        },


        function () {
            $(this).css('background-color', '#EBEBEB');
        });
        $(this).click(function () {
            document.getElementById('addradio' + i).checked = true;
            $("#add" + i).attr('class', 'orderadd');
            $("div[name=add]").slideUp();
            $("#add" + i).slideDown("normal");
            $("#otherAddText").slideUp();
            document.getElementById("other_add").checked = false;
        });
    });
};

function renderAreaSelect() {
    var country = $("#country").val();
    var defaults = {
        s1: 'register_province',
        s2: 'register_city',
        s3: 'register_country',
        v1: $("#province").val(),
        v2: $("#city").val(),
        v3: $("#country").val()
    };
    threeSelect(defaults);
};

function getFormShow(check_id1, check_id2, form_id) {
    $("#" + form_id).hide();
    $("#" + check_id2).hide();
    $("#" + check_id1).click(function () {
        $("#" + check_id1).hide();
        $("#" + check_id2).show();
        $("#" + form_id).show();
    });
    $("#" + check_id2).click(function () {
        $("#" + check_id1).show();
        $("#" + check_id2).hide();
        $("#" + form_id).hide();
    });
};

function courseCommentShow(id) {
    $.ajax({
        url: '/course/commentlist/' + id,
        type: 'get',
        dataType: 'html',
        success: function (msg) {
            $("#CommentsList").html(msg);
        }
    })
};

function courseCommentAdd(id) {
    var title = $("#comment_title").val();
    var content = $("#comment_content").val();
    if ($.trim(title) == '') {
        alert("请填写评论标题！");
        $("#comment_title").focus();
        return false;
    }
    if ($.trim(content) == '') {
        alert("请填写评论内容！");
        $("#comment_content").focus();
        return false;
    } else {
        $.ajax({
            url: '/course/commentadd/',
            type: 'post',
            cache: false,
            data: 'id=' + id + '&title=' + title + '&content=' + content,
            dataType: 'html',
            success: function (msg) {
                switch (msg) {
                case "1":
                    window.location.href = "/comment/history/" + id;
                    break;
                case "2":
                    alert("评论失败！");
                    break;
                case "3":
                    var pos = getElementPos("img" + id);
                    $("#userBox").show();
                    $("#username").focus();
                    var b = document.getElementById("userBox");
                    b.style.left = pos.x + 260 + "px";
                    b.style.top = pos.y + "px";
                    break;
                case "4":
                    alert("一分钟内不能重复评论！");
                    break;
                default:
                    alert("你输入的字符: <<" + msg + ">> 非法");
                    break;
                }
            }
        })
    }
};

function courseQuestionAdd(id) {
    var content = $("#question_content").val();
    if ($.trim(content) == '') {
        alert("请填写咨询内容！");
        $("#question_content").focus();
        return false;
    } else {
        $.ajax({
            url: '/course/questionadd/',
            type: 'post',
            cache: false,
            data: 'id=' + id + '&content=' + content,
            dataType: 'html',
            success: function (msg) {
                switch (msg) {
                case "1":
                    window.location.href = "/question/questionlist/" + id;
                    break;
                case "2":
                    alert("发表咨询失败！");
                    break;
                case "3":
                    var pos = getElementPos("img" + id);
                    $("#userBox").show();
                    $("#username").focus();
                    var b = document.getElementById("userBox");
                    b.style.left = pos.x + 260 + "px";
                    b.style.top = pos.y + "px";
                    break;
                case "4":
                    alert("一分钟内不能重复咨询！");
                    break;
                default:
                    alert("你输入的字符: <<" + msg + ">> 非法");
                    break;
                }
            }
        })
    }
};

function selectTags(tagid, showContent, selfObj) {
    var tag = document.getElementById(tagid).getElementsByTagName("li");
    var taglength = tag.length;
    for (i = 0; i < taglength; i++) {
        $("#tab" + i).attr('class', '');
    }
    selfObj.className = "on";
    for (i = 0; j = document.getElementById("tagContents" + i); i++) {
        j.style.display = "none";
    }
    $("#" + showContent).show();
};

function teacherCommentShow(id) {
    $.ajax({
        url: '/teacher/commentlist/' + id,
        type: 'get',
        dataType: 'html',
        success: function (msg) {
            $("#CommentsList").html(msg);
        }
    })
};

function teacherCommentAdd(id) {
    var title = $("#comment_title").val();
    var content = $("#comment_content").val();
    if ($.trim(title) == '') {
        alert("请填写评论标题！");
        $("#comment_title").focus();
        return false;
    }
    if ($.trim(content) == '') {
        alert("请填写评论内容！");
        $("#comment_content").focus();
        return false;
    } else {
        $.ajax({
            url: '/teacher/commentadd/',
            type: 'post',
            cache: false,
            data: 'id=' + id + '&title=' + title + '&content=' + content,
            dataType: 'html',
            success: function (msg) {
                switch (msg) {
                case "1":
                    alert("感谢您评论,只要被选精华评论就可以获得10个金币哦！详情参考学员评论规范。");
                    teacherCommentShow(id);
                    break;
                case "2":
                    alert("评论失败！");
                    break;
                case "3":
                    var pos = getElementPos("img" + id);
                    $("#userBox").show();
                    $("#username").focus();
                    var b = document.getElementById("userBox");
                    b.style.left = pos.x - 440 + "px";
                    b.style.top = pos.y - 180 + "px";
                    return false;
                    break;
                case "4":
                    alert("一分钟内不能重复评论！");
                    break;
                default:
                    alert("你输入的字符: <<" + msg + ">> 非法");
                    break;
                }
            }
        })
    }
};

function confirmcheck() {
    if (($('#isinvoice1').attr('checked') == true) && ($.trim($("#invoicehead").val()) == '')) {
        alert('请填写发票抬头！');
        $("#invoicehead").focus();
        return false;
    }
    if (($('#isinvoice1').attr('checked') == true) && ($('input[name="data[addid]"]:checked').val() == undefined)) {
        alert('请选择一个收货地址！');
        return false;
    }
    if (($('#isinvoice1').attr('checked') == true) && ($('#other_add').attr('checked') == true) && ($.trim($("#cod_name").val()) == '')) {
        alert('收货人姓名不能为空！');
        $("#cod_name").focus();
        return false;
    }
    if (($('#isinvoice1').attr('checked') == true) && ($('#other_add').attr('checked') == true) && ($.trim($("#cod_add").val()) == '')) {
        alert('详细地址不能为空！');
        $("#cod_add").focus();
        return false;
    }
    if (($('#isinvoice1').attr('checked') == true) && ($('#other_add').attr('checked') == true) && ($.trim($("#cod_phone").val()) == '')) {
        alert('联系电话不能为空！');
        $("#cod_phone").focus();
        return false;
    }
};

function codcheck() {
    if ($.trim($("#cod_name").val()) == '') {
        alert('收货人不能为空！');
        $("#cod_name").focus();
        return false;
    }
    if ($.trim($("#cod_add").val()) == '') {
        alert('详细地址不能为空！');
        $("#cod_add").focus();
        return false;
    }
    if ($.trim($("#cod_phone").val()) == '') {
        alert('联系电话不能为空！');
        $("#cod_phone").focus();
        return false;
    }
};

function zipSelect(id) {
    $.ajax({
        type: "GET",
        url: '/json/wss_zipcode.json?' + generateMixed(12),
        dataType: "json",
        timeout: 7000,
        success: function (result) {
            if (result != '') {
                $.each(result, function (i, j) {
                    if (i == id) {
                        var zipcode = j['zipcode'];
                        $('#zipcode').attr('value', zipcode);
                    }
                });
            }
        },
        error: function () {
            alert('数据读取错误..');
        }
    });
};

function pageselectCallback(page_index, jq) {
    var page_index = parseInt(page_index) > 0 ? parseInt(page_index) : 0;
    var urlPage = $("#urlPage").val() + page_index;
    var params = $("#params").val();
    $.ajax({
        url: urlPage,
        type: 'post',
        dataType: 'html',
        data: params,
        success: function (msg) {
            $("#PaginationResult").html(msg);
        }
    });
}

function initPagination(edge, display, per, page_total) {
    $(".result_pagination").pagination(page_total, {
        num_edge_entries: edge,
        num_display_entries: display,
        callback: pageselectCallback,
        items_per_page: per
    });
}

function renderPagination_comments(per) {
    var page_total = parseInt($("#pageTotal").val());
    if (page_total > 0) {
        initPagination(2, 8, per, page_total);
        if (page_total < eval(parseInt(per) + 1)) {
            $(".result_pagination").hide();
        }
    } else {
        $("#PaginationResult").html("<div align='center'>该课程暂无评论！</div>");
    }
}

function initPagination_2(edge, display, per, page_total) {
    $("#course_Pagination").pagination(page_total, {
        num_edge_entries: edge,
        num_display_entries: display,
        callback: pageselectCallback_2,
        items_per_page: per
    });
}

function pageselectCallback_2(page_index, jq) {
    var page_index = parseInt(page_index) > 0 ? parseInt(page_index) : 0;
    var urlPage = $("#course_urlPage").val() + page_index;
    $.ajax({
        url: urlPage,
        type: 'post',
        dataType: 'html',
        success: function (msg) {
            $("#course_PaginationResult").html(msg);
        }
    });
}

function favoriteAdd(course_id) {
    $.ajax({
        url: '/course/addFavorite/' + course_id,
        type: 'post',
        dataType: 'html',
        success: function (msg) {
            var dialogBox = new initDialog({
                id: 'dialogBox',
                bg: 'dialogBox_Bg',
                width: 350,
                height: 120
            });
            if (msg == '0') {
                var H=Math.max($('body').height(),$(window).height()),L=$('body').width()/2-235;
				var _mask='<div id="winMask" class="win-mask"><!--[if IE 6]><iframe frameborder="0" width="100%" height="100%" style="filter:alpha(opacity=0);opacity:0;"></iframe><![endif]--></div>';
				if($('#winMask').length==0){$('body').append(_mask);}
				$('#winMask').height(H).show();
				var pos=getElementPos("img" +course_id);
			    $("#cartLogin,.win-form-box:eq(0)").show();
			    $("#cartname").focus();
			    var b = document.getElementById("cartLogin");
			    b.style.left = L+"px";
				b.style.top = pos.y-200+"px";
				var _scroll=$('#img' +course_id).length>0?$('#img' +course_id).offset().top:50;
                //window.location.href = "/users/logReg/" + base64encode('/kc/' + course_id + '.html');
            } else {
                dialogBox.open();
                var pos = getElementPos("img" + course_id);
                var b = document.getElementById("dialogBox");
                b.style.top = pos.y - 100 + "px";
                $('#favorite_tip').html(msg);
            }
        }
    });
};

function freecourseAdd(course_id) {
    $.ajax({
        url: '/course/addFreecourse/' + course_id,
        type: 'post',
        dataType: 'html',
        success: function (msg) {
            var dialogBox = new initDialog({
                id: 'dialogBox2',
                bg: 'dialogBox_Bg2',
                width: 350,
                height: 120
            });
            if (msg == '0') {
                var H=Math.max($('body').height(),$(window).height()),L=$('body').width()/2-235;
				var _mask='<div id="winMask" class="win-mask"><!--[if IE 6]><iframe frameborder="0" width="100%" height="100%" style="filter:alpha(opacity=0);opacity:0;"></iframe><![endif]--></div>';
				if($('#winMask').length==0){$('body').append(_mask);}
				$('#winMask').height(H).show();
				var pos=getElementPos("img" +course_id);
			    $("#cartLogin,.win-form-box:eq(0)").show();
			    $("#cartname").focus();
			    var b = document.getElementById("cartLogin");
			    b.style.left = L+"px";
				b.style.top = pos.y-200+"px";
				var _scroll=$('#img' +course_id).length>0?$('#img' +course_id).offset().top:50;
                //window.location.href = "/users/logReg/" + base64encode('/kc/' + course_id + '.html');
            } else if (msg == '1') {
                window.location.href = "http://i.xueersi.com/MyFreeCourses/";
            } else {
                dialogBox.open();
                var pos = getElementPos("img" + course_id);
                var b = document.getElementById("dialogBox");
                b.style.top = pos.y - 100 + "px";
                $('#freecourse_tip').html(msg);
            }
        }
    });
};

//function courseLogin(v, course_id) {
//    var username = $.trim($("#course_username").val());
//    var password = $.trim($("#course_password").val());
//    var params = "username=" + username + "&password=" + password;
//    $.ajax({
//        type: "post",
//        url: '/users/userLogin',
//        dataType: "json",
//        timeout: 7000,
//        data: params,
//        success: function (msg) {
//            if (msg.sign == true) {
//                $('#winMask,#cartLogin,.win-form-box:eq(1)').hide();
//                $("#userInfo1").hide();
//                $("#userInfo2").show();
//                $("#userLoginname").html(username);
//                if (v == 'fav' && course_id > 0) {
//                    favoriteAdd(course_id);
//                }
//                if (v == 'free' && course_id > 0) {
//                    freecourseAdd(course_id);
//                }
//            } else {
//                alert(msg.loginErrorMsg);
//            }
//        },
//        error: function () {
//            alert('数据读取错误..');
//        }
//    });
//};

//function courseReg() {
//    var email = $.trim($("#email").val());
//    var password = $.trim($("#regpassword").val());
//    var confirm_password = $.trim($("#repassword").val());
//    var realname = $.trim($("#truename").val());
//    var phone = $.trim($("#mobile").val());
//    var phone_province = $.trim($("#phone_province").val());
//    var phone_city = $.trim($("#phone_city").val());
//    var grade_id = $.trim($("#grade").val());
//    var verificationCode = $.trim($("#code").val());
//    var allowClause = $.trim($("#provisions").val());
//    var ip_province = $.trim($("#ip_province").val());
//    var ip_city = $.trim($("#ip_city").val());
//    var params = "email=" + email + "&password=" + password + "&confirm_password=" + confirm_password + "&realname=" + realname + "&phone=" + phone + "&phone_province=" + phone_province + "&phone_city=" + phone_city + "&grade_id=" + grade_id + "&verificationCode=" + verificationCode + "&allowClause=" + allowClause + "&ip_province=" + ip_province + "&ip_city=" + ip_city;
//    $.ajax({
//        type: "post",
//        url: '/users/aRegister',
//        dataType: "json",
//        timeout: 7000,
//        data: params,
//        success: function (msg) {
//            if (msg.sign == true) {
//                $("#cartLogin").html('<div class="cartRegSucc"><img src="/img/smiling-face.gif" /><span class="cartRegWord">注册成功！</span></div>');
//                cartRegSuccClose();
//                $("#userInfo1").hide();
//                $("#userInfo2").show();
//                $("#userLoginname").html(email);
//            } else {
//                alert(msg.regErrorMsg);
//            }
//        },
//        error: function () {
//            alert('数据读取错误..');
//        }
//    });
//};
var regTimer = 0,
    regInterval;

function cartRegSuccClose() {
    regInterval = setInterval(function () {
        if (regTimer > 2) {
            $('#winMask,#cartLogin,.win-form-box:eq(1)').hide();
            clearInterval(regInterval);
        } else {
            regTimer++;
        }
    },
    1000);
};
var swfobject = function () {
    var D = "undefined",
        r = "object",
        S = "Shockwave Flash",
        W = "ShockwaveFlash.ShockwaveFlash",
        q = "application/x-shockwave-flash",
        R = "SWFObjectExprInst",
        x = "onreadystatechange",
        O = window,
        j = document,
        t = navigator,
        T = false,
        U = [h],
        o = [],
        N = [],
        I = [],
        l, Q, E, B, J = false,
        a = false,
        n, G, m = true,
        M = function () {
        var aa = typeof j.getElementById != D && typeof j.getElementsByTagName != D && typeof j.createElement != D,
            ah = t.userAgent.toLowerCase(),
            Y = t.platform.toLowerCase(),
            ae = Y ? /win/.test(Y) : /win/.test(ah),
        ac = Y ? /mac/.test(Y) : /mac/.test(ah),
        af = /webkit/.test(ah) ? parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/, "$1")) : false,
        X = !+"\v1",
        ag = [0, 0, 0],
        ab = null;
        if (typeof t.plugins != D && typeof t.plugins[S] == r) {
            ab = t.plugins[S].description;
            if (ab && !(typeof t.mimeTypes != D && t.mimeTypes[q] && !t.mimeTypes[q].enabledPlugin)) {
                T = true;
                X = false;
                ab = ab.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
                ag[0] = parseInt(ab.replace(/^(.*)\..*$/, "$1"), 10);
                ag[1] = parseInt(ab.replace(/^.*\.(.*)\s.*$/, "$1"), 10);
                ag[2] = /[a-zA-Z]/.test(ab) ? parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/, "$1"), 10) : 0
            }
        } else {
            if (typeof O.ActiveXObject != D) {
                try {
                    var ad = new ActiveXObject(W);
                    if (ad) {
                        ab = ad.GetVariable("$version");
                        if (ab) {
                            X = true;
                            ab = ab.split(" ")[1].split(",");
                            ag = [parseInt(ab[0], 10), parseInt(ab[1], 10), parseInt(ab[2], 10)]
                        }
                    }
                } catch(Z) {}
            }
        }
        return {
            w3: aa,
            pv: ag,
            wk: af,
            ie: X,
            win: ae,
            mac: ac
        }
    }(),
        k = function () {
        if (!M.w3) {
            return
        }
        if ((typeof j.readyState != D && j.readyState == "complete") || (typeof j.readyState == D && (j.getElementsByTagName("body")[0] || j.body))) {
            f()
        }
        if (!J) {
            if (typeof j.addEventListener != D) {
                j.addEventListener("DOMContentLoaded", f, false)
            }
            if (M.ie && M.win) {
                j.attachEvent(x, function () {
                    if (j.readyState == "complete") {
                        j.detachEvent(x, arguments.callee);
                        f()
                    }
                });
                if (O == top) {
                    (function () {
                        if (J) {
                            return
                        }
                        try {
                            j.documentElement.doScroll("left")
                        } catch(X) {
                            setTimeout(arguments.callee, 0);
                            return
                        }
                        f()
                    })()
                }
            }
            if (M.wk) {
                (function () {
                    if (J) {
                        return
                    }
                    if (!/loaded|complete/.test(j.readyState)) {
                        setTimeout(arguments.callee, 0);
                        return
                    }
                    f()
                })()
            }
            s(f)
        }
    }();

    function f() {
        if (J) {
            return
        }
        try {
            var Z = j.getElementsByTagName("body")[0].appendChild(C("span"));
            Z.parentNode.removeChild(Z)
        } catch(aa) {
            return
        }
        J = true;
        var X = U.length;
        for (var Y = 0; Y < X; Y++) {
            U[Y]()
        }
    }
    function K(X) {
        if (J) {
            X()
        } else {
            U[U.length] = X
        }
    }
    function s(Y) {
        if (typeof O.addEventListener != D) {
            O.addEventListener("load", Y, false)
        } else {
            if (typeof j.addEventListener != D) {
                j.addEventListener("load", Y, false)
            } else {
                if (typeof O.attachEvent != D) {
                    i(O, "onload", Y)
                } else {
                    if (typeof O.onload == "function") {
                        var X = O.onload;
                        O.onload = function () {
                            X();
                            Y()
                        }
                    } else {
                        O.onload = Y
                    }
                }
            }
        }
    }
    function h() {
        if (T) {
            V()
        } else {
            H()
        }
    }
    function V() {
        var X = j.getElementsByTagName("body")[0];
        var aa = C(r);
        aa.setAttribute("type", q);
        var Z = X.appendChild(aa);
        if (Z) {
            var Y = 0;
            (function () {
                if (typeof Z.GetVariable != D) {
                    var ab = Z.GetVariable("$version");
                    if (ab) {
                        ab = ab.split(" ")[1].split(",");
                        M.pv = [parseInt(ab[0], 10), parseInt(ab[1], 10), parseInt(ab[2], 10)]
                    }
                } else {
                    if (Y < 10) {
                        Y++;
                        setTimeout(arguments.callee, 10);
                        return
                    }
                }
                X.removeChild(aa);
                Z = null;
                H()
            })()
        } else {
            H()
        }
    }
    function H() {
        var ag = o.length;
        if (ag > 0) {
            for (var af = 0; af < ag; af++) {
                var Y = o[af].id;
                var ab = o[af].callbackFn;
                var aa = {
                    success: false,
                    id: Y
                };
                if (M.pv[0] > 0) {
                    var ae = c(Y);
                    if (ae) {
                        if (F(o[af].swfVersion) && !(M.wk && M.wk < 312)) {
                            w(Y, true);
                            if (ab) {
                                aa.success = true;
                                aa.ref = z(Y);
                                ab(aa)
                            }
                        } else {
                            if (o[af].expressInstall && A()) {
                                var ai = {};
                                ai.data = o[af].expressInstall;
                                ai.width = ae.getAttribute("width") || "0";
                                ai.height = ae.getAttribute("height") || "0";
                                if (ae.getAttribute("class")) {
                                    ai.styleclass = ae.getAttribute("class")
                                }
                                if (ae.getAttribute("align")) {
                                    ai.align = ae.getAttribute("align")
                                }
                                var ah = {};
                                var X = ae.getElementsByTagName("param");
                                var ac = X.length;
                                for (var ad = 0; ad < ac; ad++) {
                                    if (X[ad].getAttribute("name").toLowerCase() != "movie") {
                                        ah[X[ad].getAttribute("name")] = X[ad].getAttribute("value")
                                    }
                                }
                                P(ai, ah, Y, ab)
                            } else {
                                p(ae);
                                if (ab) {
                                    ab(aa)
                                }
                            }
                        }
                    }
                } else {
                    w(Y, true);
                    if (ab) {
                        var Z = z(Y);
                        if (Z && typeof Z.SetVariable != D) {
                            aa.success = true;
                            aa.ref = Z
                        }
                        ab(aa)
                    }
                }
            }
        }
    }
    function z(aa) {
        var X = null;
        var Y = c(aa);
        if (Y && Y.nodeName == "OBJECT") {
            if (typeof Y.SetVariable != D) {
                X = Y
            } else {
                var Z = Y.getElementsByTagName(r)[0];
                if (Z) {
                    X = Z
                }
            }
        }
        return X
    }
    function A() {
        return !a && F("6.0.65") && (M.win || M.mac) && !(M.wk && M.wk < 312)
    }
    function P(aa, ab, X, Z) {
        a = true;
        E = Z || null;
        B = {
            success: false,
            id: X
        };
        var ae = c(X);
        if (ae) {
            if (ae.nodeName == "OBJECT") {
                l = g(ae);
                Q = null
            } else {
                l = ae;
                Q = X
            }
            aa.id = R;
            if (typeof aa.width == D || (!/%$/.test(aa.width) && parseInt(aa.width, 10) < 310)) {
                aa.width = "310"
            }
            if (typeof aa.height == D || (!/%$/.test(aa.height) && parseInt(aa.height, 10) < 137)) {
                aa.height = "137"
            }
            j.title = j.title.slice(0, 47) + " - Flash Player Installation";
            var ad = M.ie && M.win ? "ActiveX" : "PlugIn",
            ac = "MMredirectURL=" + O.location.toString().replace(/&/g, "%26") + "&MMplayerType=" + ad + "&MMdoctitle=" + j.title;
            if (typeof ab.flashvars != D) {
                ab.flashvars += "&" + ac
            } else {
                ab.flashvars = ac
            }
            if (M.ie && M.win && ae.readyState != 4) {
                var Y = C("div");
                X += "SWFObjectNew";
                Y.setAttribute("id", X);
                ae.parentNode.insertBefore(Y, ae);
                ae.style.display = "none";
                (function () {
                    if (ae.readyState == 4) {
                        ae.parentNode.removeChild(ae)
                    } else {
                        setTimeout(arguments.callee, 10)
                    }
                })()
            }
            u(aa, ab, X)
        }
    }
    function p(Y) {
        if (M.ie && M.win && Y.readyState != 4) {
            var X = C("div");
            Y.parentNode.insertBefore(X, Y);
            X.parentNode.replaceChild(g(Y), X);
            Y.style.display = "none";
            (function () {
                if (Y.readyState == 4) {
                    Y.parentNode.removeChild(Y)
                } else {
                    setTimeout(arguments.callee, 10)
                }
            })()
        } else {
            Y.parentNode.replaceChild(g(Y), Y)
        }
    }
    function g(ab) {
        var aa = C("div");
        if (M.win && M.ie) {
            aa.innerHTML = ab.innerHTML
        } else {
            var Y = ab.getElementsByTagName(r)[0];
            if (Y) {
                var ad = Y.childNodes;
                if (ad) {
                    var X = ad.length;
                    for (var Z = 0; Z < X; Z++) {
                        if (! (ad[Z].nodeType == 1 && ad[Z].nodeName == "PARAM") && !(ad[Z].nodeType == 8)) {
                            aa.appendChild(ad[Z].cloneNode(true))
                        }
                    }
                }
            }
        }
        return aa
    }
    function u(ai, ag, Y) {
        var X, aa = c(Y);
        if (M.wk && M.wk < 312) {
            return X
        }
        if (aa) {
            if (typeof ai.id == D) {
                ai.id = Y
            }
            if (M.ie && M.win) {
                var ah = "";
                for (var ae in ai) {
                    if (ai[ae] != Object.prototype[ae]) {
                        if (ae.toLowerCase() == "data") {
                            ag.movie = ai[ae]
                        } else {
                            if (ae.toLowerCase() == "styleclass") {
                                ah += ' class="' + ai[ae] + '"'
                            } else {
                                if (ae.toLowerCase() != "classid") {
                                    ah += " " + ae + '="' + ai[ae] + '"'
                                }
                            }
                        }
                    }
                }
                var af = "";
                for (var ad in ag) {
                    if (ag[ad] != Object.prototype[ad]) {
                        af += '<param name="' + ad + '" value="' + ag[ad] + '" />'
                    }
                }
                aa.outerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' + ah + ">" + af + "</object>";
                N[N.length] = ai.id;
                X = c(ai.id)
            } else {
                var Z = C(r);
                Z.setAttribute("type", q);
                for (var ac in ai) {
                    if (ai[ac] != Object.prototype[ac]) {
                        if (ac.toLowerCase() == "styleclass") {
                            Z.setAttribute("class", ai[ac])
                        } else {
                            if (ac.toLowerCase() != "classid") {
                                Z.setAttribute(ac, ai[ac])
                            }
                        }
                    }
                }
                for (var ab in ag) {
                    if (ag[ab] != Object.prototype[ab] && ab.toLowerCase() != "movie") {
                        e(Z, ab, ag[ab])
                    }
                }
                aa.parentNode.replaceChild(Z, aa);
                X = Z
            }
        }
        return X
    }
    function e(Z, X, Y) {
        var aa = C("param");
        aa.setAttribute("name", X);
        aa.setAttribute("value", Y);
        Z.appendChild(aa)
    }
    function y(Y) {
        var X = c(Y);
        if (X && X.nodeName == "OBJECT") {
            if (M.ie && M.win) {
                X.style.display = "none";
                (function () {
                    if (X.readyState == 4) {
                        b(Y)
                    } else {
                        setTimeout(arguments.callee, 10)
                    }
                })()
            } else {
                X.parentNode.removeChild(X)
            }
        }
    }
    function b(Z) {
        var Y = c(Z);
        if (Y) {
            for (var X in Y) {
                if (typeof Y[X] == "function") {
                    Y[X] = null
                }
            }
            Y.parentNode.removeChild(Y)
        }
    }
    function c(Z) {
        var X = null;
        try {
            X = j.getElementById(Z)
        } catch(Y) {}
        return X
    }
    function C(X) {
        return j.createElement(X)
    }
    function i(Z, X, Y) {
        Z.attachEvent(X, Y);
        I[I.length] = [Z, X, Y]
    }
    function F(Z) {
        var Y = M.pv,
            X = Z.split(".");
        X[0] = parseInt(X[0], 10);
        X[1] = parseInt(X[1], 10) || 0;
        X[2] = parseInt(X[2], 10) || 0;
        return (Y[0] > X[0] || (Y[0] == X[0] && Y[1] > X[1]) || (Y[0] == X[0] && Y[1] == X[1] && Y[2] >= X[2])) ? true : false
    }
    function v(ac, Y, ad, ab) {
        if (M.ie && M.mac) {
            return
        }
        var aa = j.getElementsByTagName("head")[0];
        if (!aa) {
            return
        }
        var X = (ad && typeof ad == "string") ? ad : "screen";
        if (ab) {
            n = null;
            G = null
        }
        if (!n || G != X) {
            var Z = C("style");
            Z.setAttribute("type", "text/css");
            Z.setAttribute("media", X);
            n = aa.appendChild(Z);
            if (M.ie && M.win && typeof j.styleSheets != D && j.styleSheets.length > 0) {
                n = j.styleSheets[j.styleSheets.length - 1]
            }
            G = X
        }
        if (M.ie && M.win) {
            if (n && typeof n.addRule == r) {
                n.addRule(ac, Y)
            }
        } else {
            if (n && typeof j.createTextNode != D) {
                n.appendChild(j.createTextNode(ac + " {" + Y + "}"))
            }
        }
    }
    function w(Z, X) {
        if (!m) {
            return
        }
        var Y = X ? "visible" : "hidden";
        if (J && c(Z)) {
            c(Z).style.visibility = Y
        } else {
            v("#" + Z, "visibility:" + Y)
        }
    }
    function L(Y) {
        var Z = /[\\\"<>\.;]/;
        var X = Z.exec(Y) != null;
        return X && typeof encodeURIComponent != D ? encodeURIComponent(Y) : Y
    }
    var d = function () {
        if (M.ie && M.win) {
            window.attachEvent("onunload", function () {
                var ac = I.length;
                for (var ab = 0; ab < ac; ab++) {
                    I[ab][0].detachEvent(I[ab][1], I[ab][2])
                }
                var Z = N.length;
                for (var aa = 0; aa < Z; aa++) {
                    y(N[aa])
                }
                for (var Y in M) {
                    M[Y] = null
                }
                M = null;
                for (var X in swfobject) {
                    swfobject[X] = null
                }
                swfobject = null
            })
        }
    }();
    return {
        registerObject: function (ab, X, aa, Z) {
            if (M.w3 && ab && X) {
                var Y = {};
                Y.id = ab;
                Y.swfVersion = X;
                Y.expressInstall = aa;
                Y.callbackFn = Z;
                o[o.length] = Y;
                w(ab, false)
            } else {
                if (Z) {
                    Z({
                        success: false,
                        id: ab
                    })
                }
            }
        },
        getObjectById: function (X) {
            if (M.w3) {
                return z(X)
            }
        },
        embedSWF: function (ab, ah, ae, ag, Y, aa, Z, ad, af, ac) {
            var X = {
                success: false,
                id: ah
            };
            if (M.w3 && !(M.wk && M.wk < 312) && ab && ah && ae && ag && Y) {
                w(ah, false);
                K(function () {
                    ae += "";
                    ag += "";
                    var aj = {};
                    if (af && typeof af === r) {
                        for (var al in af) {
                            aj[al] = af[al]
                        }
                    }
                    aj.data = ab;
                    aj.width = ae;
                    aj.height = ag;
                    var am = {};
                    if (ad && typeof ad === r) {
                        for (var ak in ad) {
                            am[ak] = ad[ak]
                        }
                    }
                    if (Z && typeof Z === r) {
                        for (var ai in Z) {
                            if (typeof am.flashvars != D) {
                                am.flashvars += "&" + ai + "=" + Z[ai]
                            } else {
                                am.flashvars = ai + "=" + Z[ai]
                            }
                        }
                    }
                    if (F(Y)) {
                        var an = u(aj, am, ah);
                        if (aj.id == ah) {
                            w(ah, true)
                        }
                        X.success = true;
                        X.ref = an
                    } else {
                        if (aa && A()) {
                            aj.data = aa;
                            P(aj, am, ah, ac);
                            return
                        } else {
                            w(ah, true)
                        }
                    }
                    if (ac) {
                        ac(X)
                    }
                })
            } else {
                if (ac) {
                    ac(X)
                }
            }
        },
        switchOffAutoHideShow: function () {
            m = false
        },
        ua: M,
        getFlashPlayerVersion: function () {
            return {
                major: M.pv[0],
                minor: M.pv[1],
                release: M.pv[2]
            }
        },
        hasFlashPlayerVersion: F,
        createSWF: function (Z, Y, X) {
            if (M.w3) {
                return u(Z, Y, X)
            } else {
                return undefined
            }
        },
        showExpressInstall: function (Z, aa, X, Y) {
            if (M.w3 && A()) {
                P(Z, aa, X, Y)
            }
        },
        removeSWF: function (X) {
            if (M.w3) {
                y(X)
            }
        },
        createCSS: function (aa, Z, Y, X) {
            if (M.w3) {
                v(aa, Z, Y, X)
            }
        },
        addDomLoadEvent: K,
        addLoadEvent: s,
        getQueryParamValue: function (aa) {
            var Z = j.location.search || j.location.hash;
            if (Z) {
                if (/\?/.test(Z)) {
                    Z = Z.split("?")[1]
                }
                if (aa == null) {
                    return L(Z)
                }
                var Y = Z.split("&");
                for (var X = 0; X < Y.length; X++) {
                    if (Y[X].substring(0, Y[X].indexOf("=")) == aa) {
                        return L(Y[X].substring((Y[X].indexOf("=") + 1)))
                    }
                }
            }
            return ""
        },
        expressInstallCallback: function () {
            if (a) {
                var X = c(R);
                if (X && l) {
                    X.parentNode.replaceChild(l, X);
                    if (Q) {
                        w(Q, true);
                        if (M.ie && M.win) {
                            l.style.display = "block"
                        }
                    }
                    if (E) {
                        E(B)
                    }
                }
                a = false
            }
        }
    }
}();
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-18133958-1']);
_gaq.push(['_setDomainName', '.xueersi.com']);
_gaq.push(['_setAllowHash', false]);
if (typeof XES_SETVAR != 'undefined') {
    _gaq.push(['_setVar', XES_SETVAR]);
}
if (typeof XES_KEY != 'undefined') {
    _gaq.push(['_trackPageview', XES_KEY]);
} else {
    _gaq.push(['_trackPageview']);
}(function () {
    var ga = document.createElement('script');
    ga.type = 'text/javascript';
    ga.async = true;
    ga.src = ('https:' == document.location.protocol ? ' https://ssl' : ' http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(ga, s);
})();
(function () {
    var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
    document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F549ef0dd2995123b88de966409bc8a38' type='text/javascript'%3E%3C/script%3E"));
})();

function base64encode(str) {
    var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    var out, i, len;
    var c1, c2, c3;
    len = str.length;
    i = 0;
    out = "";
    while (i < len) {
        c1 = str.charCodeAt(i++) & 0xff;
        if (i == len) {
            out += base64EncodeChars.charAt(c1 >> 2);
            out += base64EncodeChars.charAt((c1 & 0x3) << 4);
            out += "==";
            break;
        }
        c2 = str.charCodeAt(i++);
        if (i == len) {
            out += base64EncodeChars.charAt(c1 >> 2);
            out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
            out += base64EncodeChars.charAt((c2 & 0xF) << 2);
            out += "=";
            break;
        }
        c3 = str.charCodeAt(i++);
        out += base64EncodeChars.charAt(c1 >> 2);
        out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
        out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));
        out += base64EncodeChars.charAt(c3 & 0x3F);
    }
    return out;
}
var USERNAME;
$.getJSON('http://' + localhostName + '/users/aGetUsername?callback=?', function (result) {
    USERNAME = result.username;
});

function checkLogin() {
    if (USERNAME != '') {
        return true;
    } else {
        return false;
    }
}
$(function(){
	var num = $('.link_list li').size();
	if(num > 16){
		var html = $('.link_list').html();
		$('#link_list_2').append(html);
		var speed0=60;
		var link_body= document.getElementById('link_body');
		var link_list_1= document.getElementById('link_list_1');
		var link_list_2= document.getElementById('link_list_2');
		function Marquee0(){
			if(link_list_2.offsetHeight-link_body.scrollTop<=0)
				link_body.scrollTop-=link_list_1.offsetHeight
			else{
				link_body.scrollTop++
			}
		}
		var MyMar0=setInterval(Marquee0,speed0)
		link_body.onmouseover=function() {clearInterval(MyMar0)}
		link_body.onmouseout=function() {MyMar0=setInterval(Marquee0,speed0)}
	}
})